import { GLType } from "./Const";

export function glTypeBytes(t: GLType) {
    switch (t) {
        case GLType.INT8: return 1;
        case GLType.UINT8: return 1;
        case GLType.INT16: return 2;
        case GLType.UINT16: return 2;
        case GLType.INT32: return 4;
        case GLType.UINT32: return 4;
        case GLType.FLOAT32: return 4;
        default: cc.warn(`Unknown Type: ${t}`);
    }
    return 0;
}


export function InitIndicesToSingleQuad(indices: Uint16Array) {
    if(indices.length % 6 !== 0) {
        cc.warn(`Indices not for quad`);
        return;
    }
    
    let count = indices.length / 6;
    for (let i = 0, idx = 0; i < count; i++) {
        let vertextID = i * 4;
        
        indices[idx++] = vertextID;
        indices[idx++] = vertextID + 1;
        indices[idx++] = vertextID + 2;

        indices[idx++] = vertextID + 1;
        indices[idx++] = vertextID + 3;
        indices[idx++] = vertextID + 2;
    }
}

export function InitIndicesToContinousQuad(indices: Uint16Array) {
    if(indices.length % 6 !== 0) {
        cc.warn(`Indices not for quad`);
        return;
    }
    
    let count = indices.length / 6;
    for (let i = 0, idx = 0; i < count; i++) {
        let vertextID = i * 2;

        indices[idx++] = vertextID;
        indices[idx++] = vertextID + 2;
        indices[idx++] = vertextID + 1;

        indices[idx++] = vertextID + 2;
        indices[idx++] = vertextID + 3;
        indices[idx++] = vertextID + 1;
    }
}